package com.jh.shadeearray;


//42번
public class Shallow_De_Array 
{
	int[] day = {1,2,3,4,5};
	
	public void shallowCopy()
	{
		int[] shallow = day; //쉘로우 카피 : 주소값에 의한 복사
		this.print(day);
		this.print(shallow);
		
		shallow[0] = 100;
		
		this.print(day);
		this.print(shallow);
	}
	
	public void print(int[] array)
	{
		for (int i = 0; i < array.length; i++) 
		{
			System.out.print(array[i] + "\t");
		}System.out.println("");
	}
	
	public void deepCopy()
	{
		//System.arrayCopy() 값을 복사
		//argument (원본객체,복사할 위치 index, 복사할 객체, 복사 대상 위치 index, 복사길이)
		int[] deep = new int[day.length];
		System.arraycopy(day, 0, deep, 0, day.length);
		
		this.print(day);
		
		this.print(deep);
		
		deep[0] = 600;
		
		this.print(day);
		
		this.print(deep);
	}
	
	public void copyArray()
	{
		int[] copyArray = new int[day.length];
		for (int i = 0; i < day.length; i++) 
		{
			copyArray[i] = day[i];
		}
		
		this.print(day);
		this.print(copyArray);
		
		copyArray[0] = 888;
		this.print(day);
		this.print(copyArray);
	}
}
